home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 1 / Amiga Tools.iso / egs-tools / egs_demo-version / egs_devels / examples / stack_language / stack-language.c < prev   
Text File  |  1994-06-06  |  10KB  |  360 lines

  1. /*
  2. **  Author: Markus van Kempen
  3. **  Date  : 17 Nov 1992
  4. **
  5. **  File  : Stack-Language.c
  6. **
  7. **  (c) by VIONA-Development 1992/93
  8. **
  9. **
  10. **  HOW TO USE THE INTUIGFX STACK-LANGUAGE
  11. **
  12. **
  13. **  This is an expamle for IntuiGfx.
  14. **  The IntuiGfx.h includes a stack language.
  15. **  This language is used for drawing, building gadgets,
  16. **  menus a.so.
  17. **
  18. **  You could use (call/run) the stack-language in serveral ways.
  19. **
  20. **  1. In structures as little programs
  21. **  2. With the interpeter "EI_Interpret" a.so.
  22. **
  23. **  The stack language has many functions and commands
  24. **  (see IntuiGfx.h and IntuiGfx.doc).
  25. **
  26. **  Please read the IntuiGfx.doc to understand how
  27. **  the stack-language works and see the following paragraph.
  28. **
  29. **  To help you to use the language for your own application
  30. **  we want to build an example.
  31. **
  32. **  We build a BoolGagdet with a triangle in it.
  33. **  At first you should know how to open a EGS-Window, because
  34. **  we need a window to display the gadget.
  35. **
  36. **  If you have a window structure, you should give
  37. **  the address of the BoolGadget to the window
  38. **  before you open it. Like:
  39. **
  40. **       newwin.gadgets=&myBoolGadget;
  41. **
  42. **  At first we make a normale triangle.
  43. **  For this work we need the following commands:
  44. **
  45. **  IG_CDark    = Get the dark color and put it on the stack
  46. **  IG_Color    = Set color dark (first stack parameter)
  47. **
  48. **  IG_GETFI+0  = Get the 0. frame parameter and put it on the stack
  49. **  IG_GETFI+1  = Get the 1. frame parameter and put it on the stack
  50. **
  51. **  IG_Const+2  = Put 2 on the stack
  52. **  IG_IDIV     = Divide parameter[stack-1] / para[stack-0]
  53. **                Like:  IG_GETFI+0,IG_Const+2,IG_IDIV,
  54. **                           X     ,     2      ,   /   (HP)
  55. **  IG_Move     = Move the cursor to the pos. stack-1,stack-0
  56. **  IG_Draw     = Draws a line from the current pos. the
  57. **                pos. stack-1,-stack-0
  58. **
  59. **  IG_NEG      = Negation from the stack parameter - 0
  60. **
  61. **  IG_RTF+2    = Remove 2 frameparamter and returns to the caller
  62. **
  63. **
  64. **  Here comes the routine:
  65. **
  66. **
  67. ** IntuiGfx:
  68. **
  69. ** Trinagle draws a triangle in a frame given by
  70. ** width an height. In the following description
  71. ** is shown how the routine draws the triangle.
  72. ** To understand it, please think like a plotter
  73. ** and take the positions as relative coordinates.
  74. **
  75. ** Triangle positions are:
  76. **
  77. ** POS       X            Y
  78. **
  79. ** 1   =  width/2  ,  height/2     | Move to the position
  80. **
  81. ** 2   = -width/2  ,  height/2     | Draw to the position
  82. **
  83. ** 3   =  width    ,     0         | Draw
  84. **
  85. ** 4   = -width/2  , -height/2     | Draw
  86. **
  87. **
  88. **        0                    Loction
  89. **       0############         ------> + x
  90. **        |   BOX    |         |
  91. **      / |    1,4   |         |
  92. **    h   |    /\    |         |
  93. **      \ |   /  \   |         |
  94. **        | 2------3 |--      \/
  95. **        |    dx    |dx      + y
  96. **        ############--
  97. **        |dx|    |dx|
  98. **                         **  dx is use in the second part !
  99. **          \   /
  100. **            w
  101. **
  102. ** STACK for Input:
  103. **                   +1 = width
  104. **                   +0 = height
  105. **
  106. */
  107.  
  108. ULONG triangle  [] = {
  109. /* NO.*/
  110. /* 1  */ IG_CTxtFront,IG_Color,          /* Set Color              */
  111. /* 2  */ IG_GETFI+1,IG_Const+2,IG_IDIV,  /* width / 2  = x         */
  112. /* 3  */ IG_GETFI+0,IG_Const+2,IG_IDIV,  /* height/ 2  = y         */
  113. /* 4  */ IG_Move,                        /* move to Pos x,y        */
  114.  
  115. /* 5  */ IG_GETFI+1,IG_Const+2,
  116. /* 6  */ IG_IDIV,IG_NEG,                 /* (width / 2)*(-1)  = x  */
  117. /* 7  */ IG_GETFI+0,IG_Const+2,IG_IDIV,  /* (height/ 2)       = y  */
  118. /* 8  */ IG_Draw,
  119.  
  120.          IG_GETFI+1,IG_Const+0,IG_Draw,  /* x= width, y = 0        */
  121.  
  122.          IG_GETFI+1,IG_Const+2,
  123.          IG_IDIV,IG_NEG,
  124.                                          /* (width / 2)*(-1)  = x  */
  125.          IG_GETFI+0,IG_Const+2,
  126.          IG_IDIV,IG_NEG,
  127.                                          /* (height/ 2)*(-1)  = y  */
  128.          IG_Draw,
  129. /*
  130. **  for using only this routine in gadget structure please replace
  131. **
  132. **        IG_RTF+2 with IG_RTS
  133. */
  134.  
  135.          IG_RTF+2                        /* Remove parameter,      */
  136. };                                       /* and returns            */
  137.  
  138. /*
  139. ** To test the routine please change the line in the
  140. ** gadget structure at the end of the text and compile it.
  141. **
  142. **      (IG_IntuiGfxPtr) &triangle,      * active          *
  143. **
  144. ** Please play with the routine and his parameter.
  145. ** For example:
  146. **             Change the height to bring the triangle
  147. **             in the top of the gadget
  148. ** see line 3
  149. **             IG_GETFI+0,IG_Const+20,IG_IDIV,
  150. **                                 ^^
  151. ** a.s.o. ....
  152. **
  153. **
  154. ** 2. The next step is
  155. **
  156. ** We want that the triangle routine uses a specified
  157. ** distance from the gadget border.
  158. **
  159. ** For this work we need the parameter dx (see upper).
  160. ** dx tells us the distance from the triangle to the bottom and
  161. ** border of the gadget.
  162. **
  163. ** Commands are used:
  164. **
  165. ** IG_Locate00 = locate to 0,0
  166. **
  167. ** IG_Locate   = locate to x,y [stack-1,stack-0]
  168. **
  169. ** IG_JSR      = jump to the sub routine on the parameter stack-0
  170. **
  171. **
  172. **
  173. ** The algorithm is:
  174. **
  175. ** We locate the cursor to a new position (dx/2,dx/2).
  176. **                                          x  , y
  177. ** then we substitude dx from the width,height
  178. ** and call the triangle routine.
  179. **
  180. ** call triangle to draw.
  181. **
  182. ** see below:
  183. **
  184. */
  185.  
  186. /*
  187. **
  188. ** IntuiGfx
  189. **
  190. ** Prepaed the parameter for triangle.
  191. ** Set the locations for the zero point.
  192. ** And subs the offset from the frame (width,height).
  193. **
  194. ** This give us the posibilities of scalable gadgets.
  195. **
  196. **
  197. ** STACK:
  198. **       0 = height
  199. **       1 = width
  200. **       2 = dx
  201. **
  202. **/
  203.  
  204. ULONG sc_triangle [] = {
  205.                          IG_GETFI+2,IG_Const+2,IG_IDIV,
  206.                          IG_GETFI+2,IG_Const+2,IG_IDIV,
  207.                          IG_Locate,
  208.                          IG_GETFI+1,IG_GETFI+2,IG_SUB,
  209.                          IG_GETFI+0,IG_GETFI+2,IG_SUB,
  210.                          (ULONG)&triangle,IG_JSR,IG_Locate00,
  211.                          IG_RTF+3};
  212. /*
  213. **
  214. ** But at first we must build a calling routine
  215. ** with the parameter dx.
  216. **
  217. ** The algo.
  218. **
  219. ** 1. Locate to 0,0
  220. **
  221. ** 2. Put the offset on the stack
  222. **    (dx must mod 2, because we divide the int by 2)
  223. **
  224. ** 3. put with on the stack
  225. **
  226. ** 4. put height on the stack
  227. **
  228. ** 5. call sc_triangle
  229. **
  230. ** Here comes the routine for the algo.
  231. **
  232. */
  233.  
  234. /*
  235. ** IntuiGfx - routine for marking selected menu item
  236. **      1     0
  237. ** ( width, height)
  238. */
  239.  
  240. ULONG myGFX         [] ={
  241.                          IG_Locate00,
  242.                          IG_Const+64,   /* Offset from the border */
  243.                          IG_GETFI+1,
  244.                          IG_GETFI+0,
  245.                          (ULONG)&sc_triangle,IG_JSR,
  246.                          IG_RTS};
  247.  
  248.  
  249. /*
  250. ** --------------------------------------------------------------
  251. **
  252. ** To test the routine please change the line in the
  253. ** gadget structure at the end of the text and compile it.
  254. **
  255. **           (IG_IntuiGfxPtr) &myGFX,        * active          *
  256. **
  257. ** Make changes with the offset and see what happens.
  258. **
  259. **
  260. ** 3.
  261. **
  262. ** The thrid step is to make a scaleable Gadget.
  263. ** That means a gadget is automatical resizing
  264. ** its image, if you size the window, for example.
  265. **
  266. ** For doing this work append the following lines to
  267. ** the event handling from the window.
  268. **
  269.           case EI_iSizeVerify:
  270.  
  271.                     printf("VerifySizing ! \n");
  272.  
  273.                     EI_RemoveGadget(Window,(struct EI_Gadget *)&myBoolGadget);
  274.  
  275.                     ReplyMsg ( (struct Message *)imess );
  276.                     break;
  277.  
  278.           case EI_iWindowSize:
  279.  
  280.                     printf("Sizing ! \n");
  281.  
  282.                     EI_LockIntuition();
  283.  
  284.                     myBoolGadget.class.width  = Window->width-
  285.                     myBoolGadget.class.leftEdge*2;
  286.                     myBoolGadget.class.height = Window->height-
  287.                     myBoolGadget.class.topEdge*2;
  288.                                                   * *2 for the border *
  289.  
  290.                     EI_AddGadget(Window,(struct EI_Gadget *)&myBoolGadget);
  291.  
  292.                     EI_UnlockIntuition();
  293.  
  294.                     ReplyMsg((struct Message *)imess);
  295.                     break;
  296.  
  297. **
  298. ** It is very easy, if the windowing is sizing (see VerifySizing)
  299. ** we remove the BoolGadget and get a clean window.
  300. **
  301. ** We wait for sizing finish. Then we LockEGSIntui so that nothing
  302. ** can happens.
  303. **
  304. ** After this we get from the window structure the new window size
  305. ** and put it in the BootGadget structure.
  306. **
  307. ** Then we add the gadget to the window and UnlockEGSIntui.
  308. **
  309. ** This is one way to make resizeable gadgets a other but the
  310. ** same base is to use the egsgadbox.library functions.
  311. ** (see egsgadbox.doc)
  312. **
  313. */
  314.  
  315. /************************** TEST GADGET *************************/
  316.  
  317. struct EI_BoolGadget myBoolGadget = {
  318.  
  319. /*  Gadget structure */
  320.  
  321.           {
  322.            NULL,NULL,                      /* prev,next        */
  323.            0,0,                            /* checkTop,leftEdge*/
  324.            10,10,                          /* leftEdge,topEdge */
  325.            WIN_WIDTH -20,
  326.            WIN_HEIGHT-20,
  327.                                            /* width , height   */
  328.            0x111,                          /* id               */
  329.  
  330. /*
  331.            (IG_IntuiGfxPtr) &triangle,
  332. */
  333.            (IG_IntuiGfxPtr) &myGFX,        /* active           */
  334.            NULL,                           /* pasive           */
  335.            NULL,                           /* select           */
  336.            NULL,                           /* release          */
  337.  
  338.         EI_STD_COMPLEMENT |                 /* flags           */
  339.         EI_STD_HIGHLIGHT |
  340.         EI_REL_VERIFY     |
  341.         EI_TOGGLE_SELECT  ,
  342.  
  343.            EI_BOOL_GADGET,                  /* Type            */
  344.            'A',                            /* hotkey          */
  345.            NULL,                           /* Call            */
  346.            NULL                            /* Userdata        */
  347.           },
  348.  
  349.         1,                                  /* flags=True       */
  350.                                             /* (use the Gadgetflags */
  351.         0,0,0,                              /* 3 pads           */
  352.         NULL,                               /* EI_GadgetArrayPtr*/
  353.         NULL                                /* exclude,include  */
  354.       };
  355. /*
  356. */
  357.  
  358.  
  359.  
  360.